package com.zbs.framework.common.handler;

import com.zbs.framework.common.utils.ErrEnum;
import com.zbs.framework.common.utils.ResultData;
import com.zbs.framework.common.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class FrameworkGlobalExceptionHandler {

    @ExceptionHandler(FrameworkBusinessRuntimeException.class)
    @ResponseBody //为了返回数据
    public ResultData error(FrameworkBusinessRuntimeException e) {
        Integer code = ErrEnum.SYS_ERR.getErrCode();
        if (e.getErrCode() != null) {
            code = e.getErrCode();
        }
        log.error("错误异常",e);
        return ResultUtil.error().code(code).message(e.getMessage());
    }
}
